<?php

namespace App\Models\Common\Adv\Repositories;

use App\Models\Common\Adv\Advertisement;
use App\Models\Common\Adv\Repositories\Interfaces\AdvertisementRepositoryInterface;
use App\Trip\Repository\BaseRepository;
use Illuminate\Support\Collection;

class AdvertisementRepository extends BaseRepository implements AdvertisementRepositoryInterface
{
    public function __construct(Advertisement $model)
    {
        parent::__construct($model);
    }

    public function addAdv(array $data): Advertisement
    {
        return $this->create($data);
    }

    public function listAdv(): Collection
    {
        return $this->model
            ->where('state', 1)
            ->orderByDesc('updated_at')
            ->get([
                'title',
                'appid',
                'url',
                'image',
                'updated_at',
            ]);
    }

    public function updateAdv(Advertisement $adv, array $data): bool
    {
        return $this->update($data, $adv);
    }

    public function deleteAdv(Advertisement $advertisement): bool
    {
        return $advertisement->delete();
    }
}